App({
  globalData: {
    appid: "wx0ffb48417ce6345c",
    selble: "",   //所选择蓝牙的mac
    bleUtil: "",     //蓝牙助手
    issel: "",        //是否全局初始化
    tabBarIndex: 0
  },
  onLaunch() {
    // 白名单配置
    const whiteList = ['/pages/login/login', '/pages/home/home'];
    // 检查登录状态
    const checkAuth = () => !!wx.getStorageSync('token');
    // 重写 navigateTo
    const originalNavigateTo = wx.navigateTo;
    wx.navigateTo = (options) => {
      if (checkAuth() || whiteList.includes(options.url)) {
        originalNavigateTo(options);
      } else {
        wx.redirectTo({ url: '/pages/login/login' });
      }
    };

    // 同理重写 redirectTo、reLaunch（switchTab 可根据需求处理）
    const originalRedirectTo = wx.redirectTo;
    wx.redirectTo = (options) => {
      if (checkAuth() || whiteList.includes(options.url)) {
        originalRedirectTo(options);
      } else {
        wx.redirectTo({ url: '/pages/login/login' });
      }
    };

    const originalReLaunch = wx.reLaunch;
    wx.reLaunch = (options) => {
      if (checkAuth() || whiteList.includes(options.url)) {
        originalReLaunch(options);
      } else {
        wx.reLaunch({ url: '/pages/login/login' });
      }
    };
  }
});
